(function($) {
	//alert("topdtFlow.editors.js starting......");
	var myflow = $.myflow;

	$.extend(true, myflow.editors, {
		inputEditor : function() {
			var _props, _k, _div, _src, _r;
			this.init = function(props, k, div, src, r) {
				_props = props;
				_k = k;
				_div = div;
				_src = src;
				_r = r;

				$('<input class="form-control" />').val(props[_k].value).change(
						function() {
							props[_k].value = $(this).val();
						}).appendTo('#' + _div);

				$('#' + _div).data('editor', this);
			};

			this.destroy = function() {
				$('#' + _div + ' input').each(function() {
					_props[_k].value = $(this).val();
				});
			};
		},
		setActor : function() {// 设置人员
			var _props, _k, _div, _src, _r;
			this.init = function(props, k, div, src, r) {
				_props = props;
				_k = k;
				_div = div;
				_src = src;
				_r = r;
				$('<a class="btn btn-sm btn-primary">设置</a>').click(function() {
					dialog.modal(jsBaskPath + '/workflow/flowDefin/setActor.jsp', "设置人员",true,false);
					
					var data = _props[_k].value;
					var activities = $(_r).data("activities");
					var assignerActivitys = _props[_k].assignerActivity;
					var acter =  _props[_k].actorNUM;
					var doRule = _props[_k].doRule;
					var text = _src.text();
					
					setActorDataInit(data,activities,assignerActivitys,text,acter,doRule);
					
					$("#actionerSub").unbind('click').click(
					   function(){
						  var selState = $("input[name='flag']:checked").val();
						  if(selState == 'perWay'|| selState == 'dArWay'){
							  _props[_k].value=queding();
						      _props[_k].actorModel="absolute";//relative absolute
						  
						  }else if(selState == 'starterWay' || selState == 'fromWay'){
						 	  _props[_k].value=queding();
						      _props[_k].actorModel="relative";
						  
						  }
						  dialog.alert("执行人设置成功!");
						}
					);
					
					$("#ruleSub").unbind('click').click(
					   function(){
							var ifOnlyOneCheck = $("input[name='ifOnlyOne']:checked").val();//人员限制单选框zhangyong20141114	
							if(ifOnlyOneCheck==1){
								_props[_k].actorNUM=-1;//执行规则人数的设置
							}else{
								_props[_k].actorNUM=$("#rulePerNum").val();//执行规则人数的设置
							}
						  _props[_k].doRule=$("input[name='moreDeal']:checked").val();
						  var activitys = $("input[name='activitys']:checked");
						  var activityStr = "";
						  for(var i=0;i<activitys.length;i++){
						  	if(i==0){
							  	activityStr += $.trim(activitys[i].value);
						  	}else{
							  	activityStr += ","+$.trim(activitys[i].value);
						  	}
						  }
						  _props[_k].assignerActivity=activityStr;
						  
						  dialog.alert("执行规则设置成功!");
						}
					);
				}).appendTo('#' + _div);
				$('#' + _div).data('editor', this);
			};

			this.destroy = function() {
				/*_props[_k].value=$('#myflow_actor_setting #set_text').val();
				$('#myflow_actor_setting #set_button').unbind('click');
				$('#myflow_actor_setting').hide();*/
			};
		},
		setCondition : function() {// 设置分支条件zhangyong20141211
			var _props, _k, _div, _src, _r;
			this.init = function(props, k, div, src, r) {
				_props = props;
				_k = k;
				_div = div;
				_src = src;
				_r = r;
				$('<a class="btn btn-sm btn-primary">设置</a>').click(function() {
					
					dialog.modal(jsBaskPath + '/workflow/flowDefin/setCondition.jsp', "分支条件设置",true,false);

					/*初始化树上数据的勾选*/
					var data = _props[_k].value;
					
					setConditionDataInit(data);
					
					$("#conditionSub").unbind('click').click(
					   function(){
						  _props[_k].value=quedingCondition();
						  dialog.alert("执行条件设置成功!");
						}
					);										
				}).appendTo('#' + _div);
				$('#' + _div).data('editor', this);
			};

			this.destroy = function() {
				/*_props[_k].value=$('#myflow_actor_setting #set_text').val();
				$('#myflow_actor_setting #set_button').unbind('click');
				$('#myflow_actor_setting').hide();*/
			};
		},		
		selectEditor : function(arg) {
			var _props, _k, _div, _src, _r;
			this.init = function(props, k, div, src, r) {
				_props = props;
				_k = k;
				_div = div;
				_src = src;
				_r = r;

				var sle = $('<select  class="form-control"/>').val(
						props[_k].value).change(function() {
					props[_k].value = $(this).val();
				}).appendTo('#' + _div);

				if (typeof arg === 'string') {
					$.ajax({
						type : "GET",
						url : arg,
						success : function(data) {
							var opts = eval(data);
							if (opts && opts.length) {
								for ( var idx = 0; idx < opts.length; idx++) {
									sle.append('<option value="'
											+ opts[idx].value + '">'
											+ opts[idx].name + '</option>');
								}
								sle.val(_props[_k].value);
							}
						}
					});
				} else {
					for ( var idx = 0; idx < arg.length; idx++) {
						sle.append('<option value="' + arg[idx].value + '">'
								+ arg[idx].name + '</option>');
					}
					sle.val(_props[_k].value);
				}

				$('#' + _div).data('editor', this);
			};
			this.destroy = function() {
				$('#' + _div + ' input').each(function() {
					_props[_k].value = $(this).val();
				});
			};
		}
	});

})(jQuery);